﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Reflection;

namespace JBot.Windows {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class AboutWindow : Window {
        public AboutWindow( ) {
            this.InitializeComponent( );

            this.Title = String.Format("About {0}", AssemblyTitle);
            this.labelProductName.Content = String.Format("Product: {0}", AssemblyProduct);
            this.labelVersion.Content = String.Format("Version: {0}.{1} Build {2}.{3}", AssemblyVersion);
            this.labelCompanyName.Content = String.Format("Company: {0}", AssemblyCompany);
            this.labelCopyright.Content = String.Format("Copyright: {0}", AssemblyCopyright);
            Paragraph para = new Paragraph( );
            foreach (string line in AssemblyDescription.Split('\n')) {
                para.Inlines.Add(line + "\n");
            }
            this.textBoxDescription.Document = new FlowDocument( );
            this.textBoxDescription.Document.Blocks.Add(para);
        }

        #region Assembly Attribute Accessors
        public string AssemblyTitle {
            get {
                object[ ] attributes = Assembly.GetExecutingAssembly( ).GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0) {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "") {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly( ).CodeBase);
            }
        }
        public string AssemblyProduct {
            get {
                object[ ] attributes = Assembly.GetExecutingAssembly( ).GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }
        public string[ ] AssemblyVersion {
            get {
                return Assembly.GetExecutingAssembly( ).GetName( ).Version.ToString( ).Split('.');
            }
        }
        public string AssemblyCompany {
            get {
                object[ ] attributes = Assembly.GetExecutingAssembly( ).GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        public string AssemblyCopyright {
            get {
                object[ ] attributes = Assembly.GetExecutingAssembly( ).GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }
        public string AssemblyDescription {
            get {
                object[ ] attributes = Assembly.GetExecutingAssembly( ).GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }
        #endregion

        private void Button_Click(object sender, RoutedEventArgs e) {
            this.Close( );
        }
    }
}